namespace DotNetNuke.UI.Utilities
{

    using System;
    using System.Web.UI;

    public class ClientAPICallBackResponse
    {
        public CallBackTypeCode CallBackType;
        private Page m_objPage;
        public string Response = "";
        public CallBackResponseStatusCode StatusCode;
        public string StatusDesc = "";

        public ClientAPICallBackResponse(Page objPage, CallBackTypeCode eCallBackType)
        {
            this.m_objPage = objPage;
            this.CallBackType = eCallBackType;
        }

        public void Write()
        {
            switch (this.TransportType)
            {
                case TransportTypeCode.XMLHTTP:
                    this.m_objPage.Response.AppendHeader("__DNNCAPISCSI", ((int) this.StatusCode).ToString());
                    this.m_objPage.Response.AppendHeader("__DNNCAPISCSDI", this.StatusDesc);
                    this.m_objPage.Response.Write(this.Response);
                    break;

                case TransportTypeCode.IFRAMEPost:
                {
                    string strContextID = this.m_objPage.Request.Form["ctx"];
                    this.m_objPage.Response.Write("<html><head></head><body onload=\"window.parent.dnn.xmlhttp.requests['" + strContextID + "'].complete(window.parent.dnn.dom.getById('txt', document).value);\"><form>");
                    this.m_objPage.Response.Write("<input type=\"hidden\" id=\"__DNNCAPISCSI\" value=\"" + ((int) this.StatusCode).ToString() + "\">");
                    this.m_objPage.Response.Write("<input type=\"hidden\" id=\"__DNNCAPISCSDI\" value=\"" + this.StatusDesc + "\">");
                    this.m_objPage.Response.Write("<textarea id=\"txt\">");
                    this.m_objPage.Response.Write(this.Response);
                    this.m_objPage.Response.Write("</textarea></body></html>");
                    break;
                }
            }
        }

        public TransportTypeCode TransportType
        {
            get
            {
                string str = this.m_objPage.Request.Form["ctx"];
                if ((str==null?0:str.Length) > 0)
                {
                    return TransportTypeCode.IFRAMEPost;
                }
                return TransportTypeCode.XMLHTTP;
            }
        }

        public enum CallBackResponseStatusCode
        {
            ControlNotFound = 0x194,
            GenericFailure = 400,
            InterfaceNotSupported = 0x1f5,
            OK = 200
        }

        public enum CallBackTypeCode
        {
            Simple
        }

        public enum TransportTypeCode
        {
            XMLHTTP,
            IFRAMEPost
        }
    }
}

